# htmlparser
import ssl
from urllib import request
from html.parser import HTMLParser
from collections import namedtuple

cxt = ssl._create_unverified_context()
class MyHtmlParser(HTMLParser):
    def handle_starttag(self, tag, attrs):
        # pass
        for attr in attrs:
            at = namedtuple('attr', ['key', 'value'])
            at_tr = at(*attr)
            if at_tr.key == 'content' and at_tr.value != None:
                print(at_tr.value)
            # print(attr[0])
        # print("Encountered a start tag:", tag)

    def handle_endtag(self, tag):
        pass
        # print("Encountered an end tag :", tag)

    def handle_data(self, data):
        pass
        # print("Encountered some data  :", data)

parser = MyHtmlParser()

with request.urlopen('https://www.baidu.com', context=cxt) as content:
    parser.feed(content.read().decode())
